﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace RobotEscape.Entities
{
    public class Spike : SpriteEntity
    {
        Sprite sprite;
        SpikeWall wall;
        public Spike(SpikeWall _wall)
        {
            wall = _wall;
            width = 20;
            height = 20;

            sprite = new Sprite();
            sprite.file = "Assets/images/entities.png";
            sprite.frameCount = 1;
            if (wall == SpikeWall.Left)
                sprite.x = 0;
            if (wall == SpikeWall.Top)
                sprite.x = 20;
            if (wall == SpikeWall.Right)
                sprite.x = 40;
            if (wall == SpikeWall.Bottom)
                sprite.x = 60;
            sprite.y = 100;
            sprite.width = 20;
            sprite.height = 20;
        }

        public override void Update(GameTime time)
        {
            Rectangle rect = this.uiElement as Rectangle;
            double drawX = this.PosX;
            double drawY = this.PosY;
            switch (this.wall)
            {
                case SpikeWall.Top:
                    drawY += Tile.Size;
                    break;
                case SpikeWall.Left:
                    drawX += Tile.Size;
                    break;
                case SpikeWall.Right:
                    drawX -= Tile.Size;
                    break;
                case SpikeWall.Bottom:
                    drawY -= Tile.Size;
                    break;
                default:
                    break;
            }
            Canvas.SetLeft(rect, drawX);
            Canvas.SetTop(rect, drawY);
            rect.Width = this.width;
            rect.Height = this.height;

            // animate sprite frames
            AnimateSprite(time, sprite); 
            
        }
    }
    public enum SpikeWall
    {
        Top, Left, Right, Bottom
    }
}
